<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class LoginController extends Controller
{
    //登录页面
    public function index(){

        if(\Auth::check()) return redirect("./posts");
    	return view('login/index');
    }
    //登录行为
    public function login(){
    	//验证
    	$this->validate(request(),[
    		'email' => 'required|email',
    		'password' => 'required|min:5|max:15',
    		'is_remeber' => 'integer'
    	]);
    	//逻辑
    	$user = request(['email','password']);
    	$is_remeber = boolval(request('is_remeber'));
    	if(\Auth::attempt($user,$is_remeber)){
    		return redirect('/posts');
    	}
    	//渲染
    	return \Redirect::back()->withErrors('邮箱密码不匹配');
    }
    //退出登录
    public function logout(){
    	\Auth::logout();
    	return redirect('/posts');
    }
}
